package model;

import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;

import persistency.controller.CourseHistoryController;
import persistency.controller.StudentController;

import controller.ConfigurationController;

/**
 * Vrije cursisten betalen een vast bedrag (voorbeeld 750 Euro) verminderd met 10 % per schooljaar dat ze
 *  in de voorbije 3 schooljaren  reeds in de school ingeschreven waren als cursist. 
 * @author Wim
 *
 */
public class FreeStudentDiscount implements IDiscountStrategy{

	public static final int FREE_STUDENT_DISCOUNT_YEAR_COUNT = Integer.parseInt(ConfigurationController.instance().getProperty("free_student.discount.year.count"));
	public static final float FREE_STUDENT_ANNUAL_FEE = Float.parseFloat(ConfigurationController.instance().getProperty("free_student.annual_fee"));
	@Override
	public float calculateSubmissionFee(Student student) {
		Collection<CourseHistory> coursehistories = CourseHistoryController.instance().getByStudentIDCourseHistories(student.getStudentNumber());
		int yearLimit= Calendar.getInstance().get(Calendar.YEAR) - FREE_STUDENT_DISCOUNT_YEAR_COUNT;
		HashSet<Integer> discountYears = new HashSet<Integer>();
		for(CourseHistory courseHistory: coursehistories){
			Integer courseHistoryYear = Integer.parseInt(courseHistory.getSchoolYear());
			if(courseHistoryYear >= yearLimit){
				discountYears.add(courseHistoryYear);
			}
		}
		return FREE_STUDENT_ANNUAL_FEE * ((10.0f - discountYears.size())/10);
	}

}
